package com.moneyhelper.upms.rest;

import cn.hutool.core.util.StrUtil;
import com.moneyhelper.common.rest.CommonRest;
import com.moneyhelper.upms.biz.SysMenuBiz;
import com.moneyhelper.upms.constant.ContextConstant;
import com.moneyhelper.upms.entity.SysMenu;
import com.moneyhelper.upms.vo.MenuTree;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author： ygl
 * @date： 2019/07/07
 * @Description：
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuRest extends CommonRest<SysMenuBiz, SysMenu, String> {

    @GetMapping("/tree")
    public List<MenuTree> getTree(String title) {
        Example example = new Example(SysMenu.class);
        if (StrUtil.isNotBlank(title)) {
            example.createCriteria().andLike("title", "%" + title + "%");
        }
        return MenuTree.buildTree(biz.selectByExample(example), ContextConstant.ROOT);
    }
}
